-
Notifications
You must be signed in to change notification settings - Fork 623
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(crypto): validate that digest length must be an integer between 0 and isize::MAX #3799
Conversation
These canary test failures don't seem to be related to my changes..? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work! Couple of nits.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! Thank you, @jeremyBanks. Thorough work, as per usual.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Currently, if we call
crypto.subtle.digest
/.digestSync
with a variable-length hash algorithm and length that is...usize::MAX
for WASM: it will be truncated, usually to0
, producing an incorrect result.isize::MAX
for WASM: it will trigger an internalcapacity_overflow
error from Rust'sVec
.capacity_overflow
error from Rust'sVec
.Some of this behaviour is a result of the JS-WASM translation layer, so this PR adds a check on the JavaScript side to throw a
RangeError
in these cases, before calling the Rust/WASM (which already checks that the length is valid for the specific algorithm being used).This also resolves #3798, which describes how our tests cases were already expecting errors for these cases, but the test logic had a bug that was causing the assertion errors to be suppressed. This fixes that test logic.
One might argue that this is a
BREAKING
change since it produces an observable change in behaviour (at least for the non-integer case). I'm not sure it's a significant enough to count, but feel free to rename this PR to indicate that it'sBREAKING
if you disagree.